package com.zhdl.modules.process.verify;

import com.zhdl.hardware_contact.hardware_config.entity.ProjectConfiguration;
import com.zhdl.modules.process.common.GetPLCValue;
import com.zhdl.modules.process.common.ProcessVerify;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class DistanceVerify implements ProcessVerify {
    private int runCount = 0;
    private  float distance;
    private final float interval;

    private final GetPLCValue getPLCValue;
    private final String filed;

    public DistanceVerify(float distance, float interval, GetPLCValue getPLCValue, String filed) {
        this.distance = distance;
        this.interval = interval;
        this.getPLCValue = getPLCValue;
        this.filed = filed;
    }

    public void setDistance(float distance) {
        this.distance = distance;
    }

    @Override
    public boolean verity() {
        runCount++;
        ProjectConfiguration value = getPLCValue.getValue(filed);
        if (value.getValueType() == 3){
            float current = Float.parseFloat(value.getValue());
            if (runCount%20 == 0){
                log.info("设置位置"+distance+"    当前位置"+current);
            }
            return current <= distance + interval && current >= distance - interval;
        }
        return false;
    }
}
